package training.bms.business;

import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.UniqueConstraint;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import training.framework.business.AbstractEntity;

@Entity
@Table(
	name="BLO_BLOG",
	uniqueConstraints=@UniqueConstraint(columnNames="BLO_NAME")
)
public class Blog extends AbstractEntity<Integer> {
	private Integer identifier;
	private String name;
	private String description;
	private Date creationDate;
	private List<Post> posts;
	
	public Blog() {}
	
	@Override
	public void setIdentifier(Integer identifier) {
		this.identifier = identifier;
	}

	@Override
	@Id
	@Column(name="BLO_IDENTIFIER")
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	public Integer getIdentifier() {
		return identifier;
	}

	public void setName(String name) {
		this.name = name;
	}

	
	@NotNull
	@Size(min=1, max=100, message="Please specify the name of this blog (100 characters maximum)")
	@Column(name="BLO_NAME")
	public String getName() {
		return name;
	}
		
	public void setDescription(String description) {
		this.description = description;
	}

	@Size(max=200, message="The maximum description length allowed is 200 characters")
	@Column(name="BLO_DESCRIPTION")
	public String getDescription() {
		return description;
	}

	public void setCreationDate(Date creationDate) {
		this.creationDate = creationDate;
	}
	
	@NotNull
	@Column(name="BLO_CREATION_DATE")
	@Temporal(TemporalType.DATE)
	public Date getCreationDate() {
		return creationDate;
	}

	public void setPosts(List<Post> posts) {
		this.posts = posts;
	}
	
	@OneToMany(mappedBy="blog", cascade=CascadeType.REMOVE)
	public List<Post> getPosts() {
		return posts;
	}	
}
